//
//  TBViewController.m
//  MJTableViewDemo
//
//  Created by ihope on 2018/5/10.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TBViewController.h"
#import "YYFPSLabel.h"

@interface TBViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(nonatomic,strong)UICollectionView *myCollectView;

@end

@implementation TBViewController

-(UICollectionView *)myCollectView{
    if (!_myCollectView) {
            UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        _myCollectView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
        _myCollectView.delegate = self;
        _myCollectView.dataSource = self;
        
        [_myCollectView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
    }
    return _myCollectView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self.view addSubview:self.myCollectView];
    
    YYFPSLabel *fpsLabel = [[YYFPSLabel alloc]initWithFrame:CGRectMake(20, 200, 100, 50)];
    [fpsLabel sizeToFit];
    fpsLabel.alpha = 1;
    [self.view addSubview:fpsLabel];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 3;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 0) return 2;
    else  if (section == 1) return 4;
    else return 10;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return CGSizeMake(kScreenWidth/2 - 20, 100);
    }
    else if (indexPath.section == 1) {
        return CGSizeMake(kScreenWidth/4 - 20, 100);
    }
    else{
        NSArray *array = @[@150,@100,@200,@300,@400];
        return CGSizeMake(kScreenWidth/2 - 20, [array[arc4random()%(array.count - 1)] floatValue]);
    }
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5, 5, 5, 5);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5.f;
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 5.f;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
